﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Services;

using Osiptel.HECO.BE;
using Osiptel.HECO.BL;
using System.IO;
using Microsoft.Office.Interop.Excel;
using System.Configuration;

public partial class Views_Predeterminados_Frm_RadioEnlace : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
            
    }

    //public static bool CreateExcelDocument(String[] ds, System.IO.Stream excelFileStream)
    //{
        //try
        //{
        //    using (SpreadsheetDocument document = SpreadsheetDocument.Create(excelFileStream, SpreadsheetDocumentType.Workbook))
        //    {
        //        CreateParts(ds, document);
        //    }

        //    Trace.WriteLine("Successfully created: " + excelFileStream);
        //    return true;
        //}
        //catch (Exception ex)
        //{
        //    Trace.WriteLine("Failed, exception thrown: " + ex.Message);
        //    return false;
        //}
    //}

    [WebMethod]
    public static List<ComponenteBE> ObtenerCompRE()
    {
        ComponenteBL componenteBL = new ComponenteBL();
        List<ComponenteBE> listaComponentes = new List<ComponenteBE>();
        listaComponentes = componenteBL.ObtenerCompRadioEnlace();
        return listaComponentes;
    }

    [WebMethod]
    public static List<ComponenteBE> ObtenerItemsPorIds(List<ParamPredeterminado> idsItems)
    {
        ComponenteBL componenteBL = new ComponenteBL();
        List<ComponenteBE> listaComponentes = new List<ComponenteBE>();
        listaComponentes = componenteBL.ObtenerComponentesPorIds1(idsItems);
        return listaComponentes.OrderBy(o => o.Orden).ToList();
    }

    
         [WebMethod]
    public static string DatosAExcel(List<ComponenteBE> datos)
    {
        String rpta = "";
        ExcelApp excelApp = new ExcelApp();
        rpta = excelApp.GenerarExcel(datos, "prederminadoRE");
        return rpta;
    }

         protected void lkb_descargar_Click(object sender, EventArgs e)
         {
             string filename = nombreExcel.Value;
             string path = System.Web.HttpContext.Current.Server.MapPath("~/ArchivosInversiones//" + filename);
             System.Web.HttpResponse response = System.Web.HttpContext.Current.Response;
             response.ClearContent();
             response.Clear();
             response.ContentType = "text/plain";
             response.AddHeader("Content-Disposition", "attachment; filename=" + filename + ";");
             response.TransmitFile(path);
             response.Flush();
             response.End();
         }
}